package com.alib.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
public class ConsumerNacosController {

    @Resource
    private RestTemplate restTemplate;

    @Value("${service-url.nacos-user-service}")
    private String providerServerName;

    /**
     *  nacos 测试
     * 发送 http://localhost:900/consumer/testResttemplate
     * 使用轮询
     *
     * 结果
     * 9002Hello Nacos Discovery testResttemplate
     * 9001Hello Nacos Discovery testResttemplate
     * */

    @GetMapping(value = "/consumer/{str}")
    public String echo(@PathVariable String str) {
        return restTemplate.getForObject(providerServerName + "/provider/" +  str, String.class);
    }
}

